Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR enhances trend narrative generation by replacing simple start-to-end point comparisons with piecewise linear regression analysis. The system now pulls pre-trained regression insights from the expenditure_insights table to detect nuanced trends, which are displayed in the overview narrative on the home page.
Changes:
- Introduced
get_segment_narrative()function to generate narratives from regression segments - Added new data fetching for expenditure insights via
get_expenditure_insight()query - Updated
overview_narrative()to use insight-based narratives instead of simple percentage calculations
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| queries.py | Adds query method to fetch expenditure insights from the database |
| pages/home.py | Updates overview narrative to use insight-based trend analysis and passes insights data to the narrative generator |
| components/narrative_generator.py | Implements new narrative generation logic with segment consolidation and trend detection |
| components/init.py | Exports the new get_segment_narrative function |
| app.py | Adds data store and callback for fetching expenditure insights |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
narrative_generator.py now wraps get_segment_narrative from the standalone yukinko-iwasaki/trend-narrative package, keeping the existing insight_df signature used by home.py unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds health-narrative and education-narrative paragraph elements to the functional breakdown sidebar. A new callback render_sector_narratives filters the precomputed insights by dimension_filter (Health / Education) and calls get_segment_narrative for each, using Path 1 (precomputed segments + cv_value). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
… section" This reverts commit 868132b.
health_narrative() and education_narrative() now use get_segment_narrative() from the trend-narrative package for the opening trend sentence, filtering stored-data-insights by dimension_filter == "Health" / "Education". The central/decentralized breakdown text that follows is unchanged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…n narratives Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Collaborator
Author
|
separated the logic for the trend narration at https://github.com/yukinko-iwasaki/trend-narrative the package lives on https://pypi.org/project/trend-narrative/ |
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- components/__init__.py: re-add get_segment_narrative export (used by health.py, education.py and home.py) - python-tests.yml: replace Python 3.8 with 3.9 to match trend-narrative's requires-python >= 3.9 constraint Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
weilu
approved these changes
Feb 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR enhances the trend narrative generation logic.
Previously, narratives were generated based on the simple difference between start and end points. This PR improves granularity by incorporating piecewise linear regression to detect more nuanced trends within the data.
The regression model has been pre-trained, and the relevant information is now being pulled from the insights table introduced in dime-worldbank/mega-boost#58.
The enhancement is reflected on the overview narrative